package com.coderyeah.cosmetology.controller;


import com.coderyeah.cosmetology.entity.User;
import com.coderyeah.cosmetology.service.UserService;
import com.coderyeah.cosmetology.util.Result;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lqs
 * @since 2022-05-24
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("userRegister")
    public Result userRegister(@RequestBody User user) {
        return userService.saveUser(user);
    }

    @GetMapping("list")
    public List<User> list() {
        List<User> users = userService.list();
        return users;
    }

    @GetMapping("queryById/{id}")
    public User queryById(@PathVariable Long id) {
        return userService.getById(id);
    }

    @PostMapping("onLogin")
    public Result onLogin(@RequestParam("phone") String phone, @RequestParam("password") String password, @RequestParam("code") String code) {
//        System.out.println(code + phone + password);
        return userService.onLogin(phone, password, code);
    }

    @PostMapping("modifyPwd")
    public Result modifyPwd(@RequestParam("phone") String phone, @RequestParam("newPwd") String newPwd) {
        return userService.modifyPwd(phone, newPwd);
    }

}

